package com.dangf.hzapp.widget;


import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.view.Gravity;
import android.widget.ImageView;
import android.widget.TextView;

import com.dangf.hzapp.R;

/**
 * 自定义 加载 类 控件
 * @author 韦海生
 * @date 2014年8月4日
 */
public class CustomProgressDialog extends Dialog {
	private static CustomProgressDialog customProgressDialog = null;
	
	public CustomProgressDialog(Context context){
		super(context);
	}
	
	public CustomProgressDialog(Context context, int theme) {
        super(context, theme);
    }
	
	public static CustomProgressDialog createDialog(Context context){
		customProgressDialog = new CustomProgressDialog(context,R.style.CustomProgressDialog);	//样式
		customProgressDialog.setContentView(R.layout.dialog_custom);				//布局
		customProgressDialog.getWindow().getAttributes().gravity = Gravity.CENTER;	//显示的位置
		customProgressDialog.setCancelable(false);		//是否可以撤销对话框
		return customProgressDialog;
	}
 
	
    public void onWindowFocusChanged(boolean hasFocus){
    	if (customProgressDialog == null){
    		return;
    	}
        ImageView imageView = (ImageView) customProgressDialog.findViewById(R.id.loadingmsg_image);
        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
        animationDrawable.start();
    }
 
    /**
     * 设置标题
     * @param strTitle
     * @return
     */
    public CustomProgressDialog setTitile(String strTitle){
    	return customProgressDialog;
    }
    
    /**
     * 设置提示的内容
     * @param strMessage
     * @return
     */
    public CustomProgressDialog setMessage(String strMessage){
    	TextView tvMsg = (TextView)customProgressDialog.findViewById(R.id.loadingmsg_text);
    	
    	if (tvMsg != null){
    		tvMsg.setText(strMessage);
    	}
    	
    	return customProgressDialog;
    }
    
    
}
